﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace CommonUtils
{
    public class FilterOfAlwaysRunResult : IAlwaysRunResultFilter
    {
        public void OnResultExecuting(ResultExecutingContext context)
        {
            (ReflectionUtil.GetSenderClassName() + "." + ReflectionUtil.GetSenderMethodName()
                + " start FilterOfAlwaysRunResult: "
       + context.HttpContext.Request.Path).Print();
        }

        public void OnResultExecuted(ResultExecutedContext context)
        {
            (ReflectionUtil.GetSenderClassName() + "." + ReflectionUtil.GetSenderMethodName()
                + " end FilterOfAlwaysRunResult: "
          + context.HttpContext.Request.Path).Print();
        }

        public static void AddTo(IServiceCollection services)
        {
            services.AddMvc(options => options.Filters.Add<FilterOfAlwaysRunResult>());
        }
    }
}
